/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.fca.ui.tools;

import datechooser.beans.DateChooserCombo;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTextField;

/**
 *
 * @author Romms
 */
public class ComponentManager {

    public static void enableDisableTextFields(Component [] components, boolean isEnable){
        for (int i = 0; i < components.length; i++)
        {
            components[i].setEnabled(isEnable);
        }
    }

    public static void enableDisableComponentesIn(JComponent owner, boolean isEnable){
        Object[] components = owner.getComponents();
        Object component = null;
        for (int i = 0; i < components.length; i++)
        {
            component = components[i];
            if (component instanceof JTextField)
            {
                ((JTextField)component).setEnabled(isEnable);
            }else if(component instanceof JComboBox){
                ((JComboBox)component).setEnabled(isEnable);
            }else if(component instanceof DateChooserCombo){
                ((DateChooserCombo)component).setEnabled(isEnable);
            }else if(component instanceof JCheckBox){
                ((JCheckBox)component).setEnabled(isEnable);
            }else if(component instanceof JButton){
                ((JButton)component).setEnabled(isEnable);
            }

        }
    }

    public static void enableDisableComponentesIn(Component [] components, boolean isEnable){
        for (int i = 0; i < components.length; i++)
        {
            components[i].setEnabled(isEnable);
        }
    }

    public static void cleanAllInTextFieldsIn(JComponent owner){
        Object[] components = owner.getComponents();
        Object component = null;
        for (int i = 0; i < components.length; i++)
        {
            component = components[i];
            if (component instanceof JTextField)
            {
                ((JTextField)component).setText("");
            }
        }
    }

    public static void cleanAllInTextFieldsIn(Component[] components){
        Object component = null;
        for (int i = 0; i < components.length; i++)
        {
            component = components[i];
            if (component instanceof JTextField)
            {
                ((JTextField)component).setText("");
            }
        }
    }

    public static void centerJFrame(JFrame jFrame){
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

        int w = jFrame.getSize().width;
        int h = jFrame.getSize().height;
        int x = (dim.width-w)/2;
        int y = (dim.height-h)/2;

        jFrame.setLocation(x, y);
    }

    public static void centerJDialog(JDialog jDialog){
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

        int w = jDialog.getSize().width;
        int h = jDialog.getSize().height;
        int x = (dim.width-w)/2;
        int y = (dim.height-h)/2;
        jDialog.setLocation(x, y);
    }
}
